import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import proxy from './proxy';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { injectGlobalReference } from './plugins'
import { FileWatcher } from '@xuekl/file-watcher'
import { useKoa } from '@xuekl/cli-koa'
const env = process.env.NODE_ENV

const plugins = [
  injectGlobalReference(),
  vue(),
  createSvgIconsPlugin({
    // 指定需要缓存的图标文件夹
    iconDirs: [path.resolve(process.cwd(), 'src/_find/svg-icons/svg')],
    // 指定symbolId格式
    symbolId: '[name]',
  }),
]

if (env === 'development') {
  plugins.push(
    new FileWatcher(path.resolve(process.cwd(), 'src/views/module')),
    useKoa(),
  )
}

// https://vitejs.dev/config/
export default defineConfig({
  plugins,
  resolve: {
    alias: [
      {
        find: '@',
        replacement: path.resolve(__dirname, "./src")
      },
      {
        find: '_',
        replacement: path.resolve(__dirname, "./src/_find")
      }
    ]
  },
  server: {
    proxy
  }
})
